import 'package:flutter/material.dart';

bool Win(
    Offset offset, bool qiziColor, List<Offset> offs, double width, int cell) {
  double lll = width / cell;
  String stringlever = lll.toStringAsFixed(2);
  String ll = stringlever.substring(0, stringlever.length - 1);
  double level = double.parse(ll);
  print(lll);
  print(level);
  print(Offset(offset.dx, offset.dy));

  //左
  List<Offset> l = [];
  int lLenght = 0;

  for (var x = offset.dx; x >= 0; x = x - level) {
    var item = Offset(x, offset.dy);
    if (offs.contains(item)) {
      lLenght++;
      l.add(item);
      if (lLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  // 右
  List<Offset> r = [];
  int rLenght = 0;
  for (double x = offset.dx; x <= width; x = x + level) {
    var item = Offset(x, offset.dy);
    if (offs.contains(item)) {
      rLenght++;
      r.add(item);
      if (rLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //上
  List<Offset> t = [];
  int tLenght = 0;
  for (var y = offset.dy; y >= 0; y = y - level) {
    var item = Offset(offset.dx, y);
    if (offs.contains(item)) {
      tLenght++;
      t.add(item);
      if (tLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //下
  List<Offset> b = [];
  int bLenght = 0;
  for (var y = offset.dy; y <= width; y = y + level) {
    var item = Offset(offset.dx, y);
    if (offs.contains(item)) {
      bLenght++;
      b.add(item);
      if (bLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //左上
  List<Offset> lt = [];
  int ltLenght = 0;
  for (var y = offset.dy, x = offset.dx;
      x >= 0 && y >= 0;
      y = y - level, x = x - level) {
    var item = Offset(x, y);
    if (offs.contains(item)) {
      ltLenght++;
      lt.add(item);
      if (ltLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //左下
  List<Offset> lb = [];
  int lbLenght = 0;
  for (var y = offset.dy, x = offset.dx;
      x >= 0 && y <= width;
      y = y + level, x = x - level) {
    var item = Offset(x, y);
    if (offs.contains(item)) {
      lbLenght++;
      lb.add(item);
      if (lbLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //右上
  List<Offset> rt = [];
  int rtLenght = 0;
  for (var y = offset.dy, x = offset.dx;
      x <= width && y > 0;
      y = y - level, x = x + level) {
    var item = Offset(x, y);
    if (offs.contains(item)) {
      rtLenght++;
      rt.add(item);
      if (rtLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  //右下
  List<Offset> rb = [];
  int rbLenght = 0;
  for (var y = offset.dy, x = offset.dx;
      x <= width && y <= width;
      y = y + level, x = x + level) {
    var item = Offset(x, y);
    if (offs.contains(item)) {
      rbLenght++;
      rb.add(item);
      if (rbLenght >= 5) {
        return true;
      }
    } else {
      break;
    }
  }

  if (l.length + r.length == 6) {
    return true;
  }

  if (t.length + b.length == 6) {
    return true;
  }

  if (lt.length + rb.length == 6) {
    return true;
  }

  if (rt.length + lb.length == 6) {
    return true;
  }

  return false;
}
